using System.Net;
using System.ServiceModel.Syndication;
using System.Xml;

namespace OpenWaves.Syndication
{
    public class SyndicationFeedLoader : ISyndicationFeedLoader
    {
        public SyndicationFeed LoadFeed(Url url)
        {
            try
            {
                using (var reader = new XmlTextReader(url.ToString()))
                {
                    return SyndicationFeed.Load(reader);
                }
            }
            catch (WebException e)
            {
                throw new SyndicationFeedLoaderException(url, ExceptionMessage.Format("Failed to load feed from {0}", url), e);
            }
            catch (XmlException e)
            {
                throw new SyndicationFeedLoaderException(url, ExceptionMessage.Format("Failed to load feed from {0}", url), e);
            }
        }
    }
}